package com.okq.action;

import com.okq.action.base.BaseActionSupport;
import com.okq.entity.Approval;
import com.okq.entity.User;
import com.okq.service.IApprovalService;
import com.okq.util.BaseTool;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.PrintWriter;
import java.util.List;

/**
 * 描述 : 审批Action
 * 作者 : zdl
 * 日期 : 2017/7/5 11:48
 */
public class ApprovalAction extends BaseActionSupport {
    private static final long serialVersionUID = 8477037031634966758L;
    /**
     * 审批接口
     */
    @Autowired
    private IApprovalService approvalServiceImpl;

    /**
     * 日志
     */
    private static final Logger logger = Logger.getLogger(ApprovalAction.class);

    private Approval approval;

    /**
     * 获取登录用户未审批的数据
     *
     * @return json
     */
    public String getNonApprovalList() {
        PrintWriter out = null;
        try {
            out = this.getResponse().getWriter();
            User loginUser = (User) getSession().getAttribute("loginUser");
            if (loginUser != null) {
                List<Approval> aList = approvalServiceImpl.listApprovalByUserId(loginUser.getId());
                String json = BaseTool.toJson(aList);
                out.print(json);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        } finally {
            if (out != null) {
                out.close();
            }
        }
        return null;
    }

    public Approval getApproval() {
        return approval;
    }

    public void setApproval(Approval approval) {
        this.approval = approval;
    }
}
